package com.heima.article.controller.v1;

import com.heima.article.service.ArticleHomeService;
import com.heima.model.article.dto.ArticleDto;
import com.heima.model.article.dto.ArticleHomeDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.constants.ArticleConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/v1/article")
@Api("App端文章")
public class ArticleHomeController {
    @Autowired
    private ArticleHomeService articleHomeService;
    @PostMapping("/load")
    @ApiOperation("加载首页")
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
        return ResponseResult.okResult(articleHomeService.load(dto, ArticleConstants.LOADTYPE_LOAD_MORE));
    }

    @PostMapping("/loadmore")
    @ApiOperation("加载更多")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto) {
        return ResponseResult.okResult(articleHomeService.load(dto, ArticleConstants.LOADTYPE_LOAD_MORE));
    }

    @PostMapping("/loadnew")
    @ApiOperation("加载最新")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto) {
        return ResponseResult.okResult(articleHomeService.load(dto, ArticleConstants.LOADTYPE_LOAD_NEW));
    }

    @PostMapping("/save")
    public ResponseResult save(@RequestBody ArticleDto articleDto){
        Map map = articleHomeService.submit(articleDto);
        return ResponseResult.okResult(map);
    }
}